home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Graphics;
-
- public class Primes extends Applet {
- int highest;
-
- public void init() {
- new Integer(0);
- this.highest = Integer.parseInt(((Applet)this).getParameter("highest"));
- }
-
- public void paint(Graphics g) {
- int row = 1;
- int col = 1;
- boolean[] primeArray = new boolean[this.highest + 1];
-
- for(int theNum = 1; theNum <= this.highest; ++theNum) {
- primeArray[theNum] = true;
-
- for(int i = 2; i <= theNum / 2; ++i) {
- if (theNum % i == 0) {
- primeArray[theNum] = false;
- break;
- }
- }
-
- if (primeArray[theNum]) {
- g.drawString(" " + theNum, 30 * col++, 20 * row);
- if (col == 10) {
- col = 1;
- ++row;
- }
- }
- }
-
- }
- }
-